//
//  FBSlideTableViewCell.m
//  XTXOneToOne
//
//  Created by Canny on 2018/10/31.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "FBSlideTableViewCell.h"


@interface FBSlideTableViewCell ()


@property (nonatomic,strong)UILabel * logo;

@property (nonatomic,strong)UILabel * name;

@property (nonatomic,strong)UILabel * lab1;

@property (nonatomic,strong)UILabel * lab2;

@property (nonatomic,strong)UILabel * lab3;

@property (nonatomic,strong)UIImageView * weixin;

@property (nonatomic,strong)UIImageView * alipay;

@property (nonatomic,strong)UIImageView * yinlian;


@end

@implementation FBSlideTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self initView];
    }
    return self;
}

-(void)setLab:(UILabel *)lab withColor:(UIColor *)color andFont:(CGFloat)font andText:(NSString *)text andTextAlignment:(NSTextAlignment)textAlignment{
    lab.text=text;
    lab.textColor=color;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textAlignment=textAlignment;
}


- (void)initView{
    
    self.backgroundColor=[UIColor whiteColor];
    
    UILabel * logo = [[UILabel alloc]init];
    [self addSubview:logo];
    logo.frame=CGRectMake(15, 10, 25, 25);
    [self setLab:logo withColor:[UIColor whiteColor] andFont:15 andText:@"" andTextAlignment:NSTextAlignmentCenter];
    logo.layer.cornerRadius=12.5;
    logo.clipsToBounds=YES;
    logo.backgroundColor=ThemeColor;
    _logo=logo;
    
    UILabel * name = [[UILabel alloc]init];
    [self addSubview:name];
    [self setLab:name withColor:RGB(30, 63, 89) andFont:15 andText:@"" andTextAlignment:NSTextAlignmentLeft];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(logo.mas_centerY).offset(0);
        make.left.equalTo(logo.mas_right).offset(15);
        make.right.equalTo(self.mas_right).offset(-10);
        make.height.mas_equalTo(20);
    }];
    _name=name;
    
    UIView * line1 =[[UIView alloc]init];
    [self addSubview:line1];
    line1.backgroundColor=RGB(231, 235, 238);
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(logo.mas_bottom).offset(10);
        make.height.mas_equalTo(1);
        
    }];
    
    UILabel * lab1 = [[UILabel alloc]init];
    [self addSubview:lab1];
    [self setLab:lab1 withColor:RGB(30, 63, 89) andFont:18 andText:@"加载中..." andTextAlignment:NSTextAlignmentLeft];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(line1.mas_bottom).offset(10);
        make.height.mas_equalTo(20);
        
    }];
    _lab1=lab1;
    
    UILabel * lab2 = [[UILabel alloc]init];
    [self addSubview:lab2];
    [self setLab:lab2 withColor:RGB(131, 151, 167) andFont:12 andText:@"限额 加载中..." andTextAlignment:NSTextAlignmentLeft];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(lab1.mas_bottom).offset(0);
        make.height.mas_equalTo(20);
        
    }];
    _lab2=lab2;
    
    UILabel * lab3 = [[UILabel alloc]init];
    [self addSubview:lab3];
    [self setLab:lab3 withColor:RGB(131, 151, 167) andFont:12 andText:@"数量 加载中..." andTextAlignment:NSTextAlignmentLeft];
    [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(lab2.mas_bottom).offset(0);
        make.height.mas_equalTo(20);
        
    }];
    _lab3=lab3;
    
    UIView * line2 =[[UIView alloc]init];
    [self addSubview:line2];
    line2.backgroundColor=RGB(231, 235, 238);
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.height.mas_equalTo(10);
        
    }];
    
    UIImageView * yinlian = [[UIImageView alloc]init];
    [self addSubview:yinlian];
    yinlian.image = [UIImage imageNamed:@"银行卡"];
    [yinlian mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.centerY.equalTo(lab1.mas_centerY).offset(0);
        make.height.mas_equalTo(18);
        make.width.mas_equalTo(18);
        
    }];
    _yinlian=yinlian;

    UIImageView * alipay = [[UIImageView alloc]init];
    [self addSubview:alipay];
    alipay.image = [UIImage imageNamed:@"支付宝"];
    [alipay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(yinlian.mas_left).offset(-15);
        make.centerY.equalTo(lab1.mas_centerY).offset(0);
        make.height.mas_equalTo(18);
        make.width.mas_equalTo(18);
        
    }];
    _alipay=alipay;
    
    UIImageView * weixin = [[UIImageView alloc]init];
    [self addSubview:weixin];
    weixin.image = [UIImage imageNamed:@"微信-3"];
    [weixin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(alipay.mas_left).offset(-15);
        make.centerY.equalTo(lab1.mas_centerY).offset(0);
        make.height.mas_equalTo(18);
        make.width.mas_equalTo(18);
        
    }];
    _weixin = weixin;
   
    
    UIImageView * imgVArrow = [[UIImageView alloc]init];
    [self addSubview:imgVArrow];
    [imgVArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.bottom.equalTo(self.mas_bottom).offset(-25);
        make.width.equalTo(@(6));
        make.height.equalTo(@(12));
    }];
    imgVArrow.image=[UIImage imageNamed:@"进入icon"];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}



-(void)setDataSource:(FBTradeOtcbillModel *)dataSource{
    _dataSource = dataSource;

    if (_dataSource) {
        
        NSString * name=[NSString stringWithFormat:@"%@",dataSource.name];
        if (name.length>0) {
            _logo.text = [name substringToIndex:1];
        }
        _name.text=name;
        
        FBTradeModel * FBmodel = [FBTradeModel sharedFBTradeModel];
        
        _lab1.text =[NSString stringWithFormat:@"%@ CNY",dataSource.price];
        
        _lab2.text= [NSString stringWithFormat:@"限额 %@-%@ CNY",dataSource.min_limit,dataSource.max_limit];
        
        _lab3.text = [NSString stringWithFormat:@"数量 %@ %@",dataSource.amount,FBmodel.selectedHeaderModel.symbol];
        _weixin.hidden=YES;
        _alipay.hidden=YES;
        _yinlian.hidden=YES;
        NSInteger i = 1;
        for (NSString * type in dataSource.payment) {
            if ([type containsString:@"支付宝"]) {
                
                _alipay.hidden=NO;
                [self setImgV:_alipay andIndex:i];
                
            }else if ([type containsString:@"微信"]){
                
                _weixin.hidden=NO;
                [self setImgV:_weixin andIndex:i];
                
            } else if([type containsString:@"银行卡"]){
                _yinlian.hidden=NO;
                [self setImgV:_yinlian andIndex:i];
            }
            i++;
        }
    }

    
}


-(void)setImgV:(UIImageView *)imgV andIndex:(NSInteger)index{
    
    if (index==1) {
        [imgV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-15);
            make.centerY.equalTo(self.lab1.mas_centerY).offset(0);
            make.height.mas_equalTo(18);
            make.width.mas_equalTo(18);
            
        }];
    }else if (index==2){
        [imgV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-15-15-18);
            make.centerY.equalTo(self.lab1.mas_centerY).offset(0);
            make.height.mas_equalTo(18);
            make.width.mas_equalTo(18);
        }];
    }else if (index==3){
        [imgV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-15-15-18-15-18);
            make.centerY.equalTo(self.lab1.mas_centerY).offset(0);
            make.height.mas_equalTo(18);
            make.width.mas_equalTo(18);
            
        }];
    }
    
    

}


+(CGFloat)computeHeight:(id)info{
    
    return 145;
    
}

@end




















